package com.mediaideas.videoengine.lyrics;

import android.content.Context;

import com.mediaideas.videoengine.utils.BaseAsyncTask;
import com.mediaideas.videoengine.utils.NetworkUtils;

/**
 * Created by XieMing on 2016/3/26.
 *
 * @Description 异步歌词下载器
 */
public class LyricLoader extends BaseAsyncTask<String, Void, String> {
    private final static String TAG = "LyricLoader";
    private Context mContext;
    private Callback mCallback;

    public interface Callback {
        /**
         * 歌词下载完成之后的回调
         *
         * @param result 下载回来的歌词
         */
        void onLoadLyricFinished(String result);
    }

    public LyricLoader(Context context, Callback callback) {
        mContext = context;
        mCallback = callback;
    }

    /**
     * 下载歌词 返回歌词
     *
     * @param params The parameters of the task.
     * @return
     */
    @Override
    protected String doInBackground(String... params) {
        String uri = params[0];

        if (uri != null) {
            return NetworkUtils.getContentByURI(uri);
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        if (mCallback != null && result != null) {
            mCallback.onLoadLyricFinished(result);
        }
    }
}
